package v1

import (
	"toy-car/models"
	"toy-car/pkg/e"
	"toy-car/pkg/util"

	"github.com/gin-gonic/gin"
)

// 部门信息全部
func PermModuleList(c *gin.Context) {
	var page, pageSize = util.GetPageAndSize(c)
	module_name := c.Query("module_name")

	code := e.SUCCESS

	list, total, err := models.GetAllSysPermModuleList(module_name, page, pageSize)

	if err != nil {
		code = e.ERROR
	}
	if code != e.SUCCESS {
		e.Fail(e.ERROR, nil, "", c)
		return
	}

	e.ListSuccess(list, "", page, pageSize, total, c)
}

// 权限添加
func PermModuleAdd(c *gin.Context) {
	var perm models.SysPermModule

	_ = c.ShouldBindJSON(&perm)

	// todo 菜单提交数据的校验
	data := make(map[string]interface{})

	err := models.AddSysPermModule(perm)

	if err != nil {
		e.Fail(e.ERROR, data, err.Error(), c)
		return
	}

	e.Success(data, "", c)
}
